package com.demo.websocket;

import org.springframework.stereotype.Component;

import com.corundumstudio.socketio.AckRequest;
import com.corundumstudio.socketio.SocketIOClient;
import com.outstading.plugin.netty.socketio.ObjectMessageHandler;
import com.outstading.plugin.netty.socketio.SocketSender;
import com.outstanding.framework.base.TransactionLogger;
import com.outstanding.framework.core.PendingException;


@Component
public class FallHandler extends  ObjectMessageHandler{

	@Override
	public String messageType() {
		
		return "fall";
	}

	@Override
	public void onMessage(SocketIOClient client, Object data, AckRequest ackRequest) throws PendingException {
		int num  = client.get("count");
		TransactionLogger.debug("num="+num);
		if(num%2 ==0) {
			SocketSender.sendMessageToUser(String.valueOf(num-1), messageType(), data);
		}else {
			
			SocketSender.sendMessageToUser(String.valueOf(num+1), messageType(), data);
		}
		
	}
}
